<!--审核发布-->

<template>
  <div>
    <div>
      <!--      <el-form :inline="true" :model="documentVideo" class="demo-form-inline">

             <el-form-item label="文档视频类型编号">
                <el-input v-model="documentVideo.id" placeholder="请输入文档视频类型编号"></el-input>
              </el-form-item>
              <el-form-item label="文档视频名">
                <el-input v-model="documentVideo.name" placeholder="请输入文档视频名"></el-input>
              </el-form-item>
              <el-form-item label="文档视频类型名">
                <el-select v-model="documentVideo.type" placeholder="请选择" >
                  <el-option
                      v-for="item in documentVideoTypeList"
                      :key="item.value"
                      :label="item.name"
                      :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item label="文档视频状态">
                <el-select v-model="documentVideo.status" placeholder="请选择" >
                  <el-option label="已发布" value="已发布"></el-option>
                  <el-option label="未发布" value="未发布"></el-option>
                  <el-option label="未审核" value="未审核"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="show">查询</el-button>
                <el-button type="primary" @click="clear">清空</el-button>
              </el-form-item>

              <el-form-item style="float: left">
                <el-button type="primary" @click="add">新增</el-button>
              </el-form-item>
              <el-form-item style="float: right">
                <el-button type="danger" @click="deleteByIds">批量删除选中</el-button>
              </el-form-item>

            </el-form>-->

      <div>
        <el-table
            max-height="400"
            highlight-current-row
            ref="multipleTable"
            tooltip-effect="dark"
            border
            @selection-change="handleSelectionChange"
            :data="tableData"
            style="margin: 0 auto; width: 100%;"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="id" label="编号" header-align="center" align="center"></el-table-column>
          <el-table-column prop="name" label="文档视频名" header-align="center" align="center"></el-table-column>
          <el-table-column prop="type" label="文档视频类型名" header-align="center" align="center">
            <template slot-scope="scope">
              {{ getTypeName(scope.row.type) }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="400" header-align="center" align="center">
            <template slot-scope="scope">

              <el-button
                  v-show="myInfo.role==='审核人员'"
                  size="mini"
                  type="primary"
                  plain
                  @click="updateInfo(scope.row.id)"
              >审核
              </el-button>
              <el-button
                  v-show="myInfo.role==='发布人员'"
                  size="mini"
                  type="primary"
                  plain
                  @click="updateInfo(scope.row.id)"
              >发布
              </el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>


      <el-dialog title="编辑" :visible.sync="updateVisible" :before-close="clearForm">
        <el-form v-model="updateData" size="mini">

          <el-form-item label="文件类型">
            <el-select v-model="updateData.type" placeholder="请选择" style="width:100%">
              <el-option
                  v-for="item in documentVideoTypeList"
                  :key="item.value"
                  :label="item.name"
                  :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <a target='_blank' v-if="!getDocumentOrViewType()" :href='getUrl()'>预览文档文件</a>
            <video width="100%" controls v-if="getDocumentOrViewType()">
              <source :src="getUrl()" type="video/mp4">
              您的浏览器不支持视频标签。
            </video>
          </el-form-item>
          <el-form-item label="文件名">
            <el-input v-model="updateData.name"></el-input>
          </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="clearForm()">取 消</el-button>
          <el-button v-show="myInfo.role==='审核人员'" type="primary" @click="updateForm()">审核</el-button>
          <el-button v-show="myInfo.role==='发布人员'" type="primary" @click="updateForm()">发布</el-button>
        </div>
      </el-dialog>

    </div>
    <br>
    <!--分页工具条-->
    <el-pagination
        style="position:absolute;bottom: 20px;margin-left: 40vh"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :background="background"
        :current-page="currentPage"
        :page-sizes="[5, 10]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount">
    </el-pagination>
  </div>


</template>
<script>


import {
  addDocumentVideo,
  changeDocumentVideo,
  deleteDocumentVideo,
  getAllDocumentVideo, getReviewDocumentVideoList
} from "@/api/documentVideo";
import {getDocumentVideoTypeList} from "@/api/documentVideoType";
import {getInfo} from "@/api/user";

export default {
  data() {
    return {
      background: true,
      // 每页显示的条数
      pageSize: 5,
      // 总记录数
      totalCount: 100,
      // 当前页码
      currentPage: 1,
      // 添加数据对话框是否展示的标记
      dialogVisible: false,
      // 表格数据
      tableData: [],
      documentVideo: {},
      form: {},
      posts: [],
      multipleSelection: [],
      selectedIds: [],
      documentVideoTypeList: [],
      formLabelWidth: "140px",


      //文件上传
      fileList: [],
      addOrUpdateFileList: [],//所有文件上传后的地址
      attachmentInfoShow: false,
      type: '',
      //更新
      updateVisible: false,
      updateData: {},

      myInfo: {},//操作人信息
    }
  },
  methods: {
    show() {
      let searchChoose = 0;
      if (this.myInfo.role === "发布人员") {
        searchChoose = 1;
      }
      getReviewDocumentVideoList(searchChoose, this.currentPage, this.pageSize).then((res) => {
        if (res.data.code === 1) {
          this.totalCount = res.data.data.total;
          this.tableData = res.data.data.rows;
          console.log("sss", res)
          if (this.tableData.length === 0 && this.currentPage > 1) {
            this.currentPage -= 1;
            this.show();
          }
        }
      }).catch((e) => {
      })
    },
    getDocumentVideoTypeLists() {
      getDocumentVideoTypeList().then((res) => {
        if (res.data.code === 1) {
          this.documentVideoTypeList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch((e) => {
      })
    },
    getTypeName(type) {
      const types = this.documentVideoTypeList.find(t => t.id === type);
      return types ? types.name : '';
    },
    getDocumentOrViewType() {
      console.log(this.getTypeName(this.updateData.type))
      return this.getTypeName(this.updateData.type).endsWith("视频");
    },
    getUrl() {
      return this.updateData.url;
    },
    clear() {
      this.documentVideo = {};
      this.show();
    },
    add() {
      this.documentVideo = {};
      this.addOrUpdateFileList = [];
      this.type = ''
      this.dialogVisible = true;
    },
    updateForm() {
      if (this.myInfo.role === "审核人员") {
        this.updateData.status = "未发布"
      } else if (this.myInfo.role === "发布人员") {
        this.updateData.status = "已发布"
      }
      changeDocumentVideo(this.updateData).then(res => {
        //console.log(res)
        if (res.data.code === 1) {
          this.$message.success("更新成功")
          this.updateVisible = false;
          this.show()
        } else {
          this.$message.error(res.data.msg)
          this.updateVisible = false;
        }
      }).catch(e => {
      });
    },
    clearForm() {
      this.updateData = {};
      this.updateVisible = false;
    },

    close() {
      this.dialogVisible = false;
      this.type = "";
      this.addOrUpdateFileList = [];
      this.fileList = [];
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    updateInfo(id) {
      this.updateData = this.tableData.filter(data => data.id === id)[0];
      this.updateVisible = true;
    },

    //分页
    handleSizeChange(val) {
      // 重新设置每页显示的条数
      this.pageSize = val;
      this.show();
    },
    handleCurrentChange(val) {
      // 重新设置当前页码
      this.currentPage = val;
      this.show();
    },
    getMyInfo() {
      getInfo().then((res) => {
        if (res.data.code === 1) {
          this.myInfo = res.data.data;
          this.show();
        }
      }).catch((e) => {
      })
    },


  },
  mounted() {
    this.getDocumentVideoTypeLists();
    this.getMyInfo();
    this.show();
  },
};
</script>


<style>
* {
  margin: 0;
  padding: 0;
}

.el-header {
  background-color: rgb(238, 241, 246);
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: white;
}

</style>
<script setup>
</script>
